<template>
  <view class="page">
    <Header :title="'抗遗忘复习'"></Header>
    <view class="main_container">
      <view class="main_content">
        <view class="content">
          <view class="tabs">
            <reviewTabs :current="0"></reviewTabs>
            <view class="tabs_list">
              <view
                class="tabs_item"
                :class="{ active: currentIndex === index }"
                v-for="(item, index) in typeList"
                :key="index"
                @click="handleChangeType(index)"
              >
                <text>{{ item.name }}</text>
              </view>
            </view>
          </view>
          <view class="list">
            <view class="list_content">
              <view
                class="item"
                v-for="(item, index) in list"
                :key="index"
                @click="
                  switchPage(
                    `/pages/review/review1List?chapterId=${item.chapterId}`
                  )
                "
              >
                <view class="item_index">
                  <text>{{ index + 1 }}</text>
                </view>
                <view class="item_text"> {{ item.chapterName }} </view>
                <view class="item_date"> {{ item.dateTime }} </view>
                <view class="item_num">
                  <text>{{ item.count }}</text>
                </view>
                <view
                  class="iten_state"
                  :class="{
                    active: item.complete === 0,
                  }"
                >
                  {{ item.complete === 0 ? "未完成" : "已完成" }}
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getKyw21List } from "@/api/sync";
import reviewTabs from "./reviewTabs";

export default {
  components: { reviewTabs },
  data() {
    return {
      typeList: [
        {
          name: "全部",
          type: "0",
        },
        {
          name: "今日待完成",
          type: "1",
        },
        {
          name: "过期未完成",
          type: "2",
        },
      ],
      currentIndex: 0,
      list: [],
    };
  },
  onLoad() {
    this.getData();
  },
  methods: {
    getData() {
      getKyw21List(this.typeList[this.currentIndex].type).then((res) => {
        this.list = res.data;
      });
    },
    handleChangeType(index) {
      if (this.currentIndex == index) return;
      this.currentIndex = index;
      this.getData();
    },
    switchPage(url) {
      uni.navigateTo({
        url: url,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./review1";
</style>
